package com.ggh.jinjilive.utils;

import android.text.Editable;
import android.text.TextWatcher;
import android.widget.Button;
import android.widget.EditText;

import com.blankj.utilcode.util.StringUtils;

public class VUtils {
    /**
     * 监听手机号和验证码是否填充
     * @param editText1
     * @param editText2
     */
    public static void doubleAddTextChangedListener(EditText editText1, EditText editText2, Button button){
        editText1.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                if(s.toString().length() > 1 && !StringUtils.isEmpty(editText2.getText().toString())
                        && editText2.getText().toString().length() > 0){
                    button.setEnabled(true);
                }else {
                    button.setEnabled(false);
                }

            }
        });
        editText2.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                if(s.toString().length() > 0 && !StringUtils.isEmpty(editText1.getText().toString())
                        && editText1.getText().toString().length() > 1){
                    button.setEnabled(true);
                }else {
                    button.setEnabled(false);
                }
            }
        });
    }

}
